﻿// -----------------------------------------------------------------------
// <copyright file="ValueDistributionChart.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace ClearLines.Stocks.UserInterface
{
   using System;
   using System.Collections.Generic;
   using System.Linq;
   using System.Text;
   using Domain;
   using Microsoft.Office.Interop.Excel;
   using Utilities;

   /// <summary>
   /// TODO: Update summary.
   /// </summary>
   public class ValueDistributionChart
   {
      public static void Write(StockHistory history, int horizon, int runs, Chart chart)
      {
         var projections = ProjectedValue.Run(history, horizon, runs);
         var min = (int)projections.Min();
         var max = (int)projections.Max();

         var xValues = new List<object>();
         var values = new List<object>();
         for (var value = min; value <= max; value++)
         {
            xValues.Add(value);
            var probability = (double)projections.Count(it => it >= value && it < value + 1d) / runs;
            values.Add(probability);
         }

         var data = new SeriesData(history.Symbol, xValues.ToArray(), values.ToArray());
         ChartWriter.CreateHistogram(chart, data);
      }
   }
}
